<@override name="content">
<div>
  <table class="table table-striped teble-download">
    <thead>
    <tr>
      <th width="5%">#</th>
      <th width="20%">资源名称</th>
      <th width="30%">资源描述</th>
      <th width="5%">操作系统</th>
      <th width="5%">架构</th>
      <th width="10%">访问权限</th>
      <th width="10%">下载量</th>
      <th width="5%">下载</th>
  <#if adminUser??>
      <th width="10%">编辑</th>
  </#if>
    </tr>
    </thead>
    <tbody>
      <#if resources??>
        <#list resources as resource>
        <tr>
          <td>${resource_index + 1}</td>
          <td><a href="resource/?name=${resource.name!?url}&id=${resource.id!}">${resource.name!}</a></td>
          <td>${resource.description!}</td>
          <td>${resource.os!}</td>
          <td>${resource.arch!}</td>
          <td>${resource.access!}</td>
          <td>${resource.download!}</td>
          <td><a href="resource/?name=${resource.name!?url}&id=${resource.id!}"><i class="icon-download-alt"></i></a></td>
          <#if adminUser??>
            <td><a href="editResource/${resource.id!}" class="btn btn-info" data-toggle="modal" data-target="#editModal">Edit</a></td>
          </#if>
        </tr>
        </#list>
      </#if>
    </tbody>
  </table>
</div>
  <#if adminUser??>
  <a href="#" id="resource" class="btn btn-success" data-toggle="modal" data-target="#resourceModal">Add Resource</a>
  <div class="modal hide fade" id="resourceModal">
    <form action="addResource" id="resourceForm" method="post">
      <div class="modal-header">
        <button class="close" aria-hidden="true" data-dismiss="modal" type="button">x</button>
      </div>
      <div class="modal-body">
        <div class="control-group">
          <label class="control-label" for="inputName">Name</label>
          <div class="controls">
            <input type="text" id="inputName" name="resource.name" placeholder="Resource name" autofocus required>
            <span class="help-block">You should not use the file name.</span>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="inputName">File Path</label>
          <div class="controls">
            <input type="text" class="input-large" id="inputPath" name="resource.path" placeholder="File path" required>
            <span class="help-block">You should not upload confidential file to ${downloadPath!}.</span>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="inputDescription">Description</label>
          <div class="controls">
            <textarea type="text" id="inputDescription" name="resource.description" rows="5" cols="30"></textarea>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="inputOS">OS</label>
          <div class="controls">
            <input type="text" id="inputOS" name="resource.os" value="Windows"/>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="inputArch">Arch</label>
          <div class="controls">
            <input type="text" id="inputArch" name="resource.arch"  value="x64"/>
          </div>
        </div>
        <div class="control-group">
          <label id="accessType" class="control-label accessType">Access Type</label>
          <div class="controls">
            <label class="radio inline">
              <input type="radio" class="accessType" name="resource.access" value="public" checked>
              Public
            </label>
            <label class="radio inline">
              <input type="radio" class="accessType" name="resource.access" value="private">
              Private
            </label>
            <label class="radio inline">
              <input type="radio" class="accessType" name="resource.access" value="security">
              Security
            </label>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Add</button>
        <button class="btn" data-dismiss="modal">Cancel</button>
      </div>
    </form>
  </div>

  <div class="modal hide fade" id="editModal">
    <form action="updateResource" id="editForm" method="post">
      <div class="modal-header">
        <button class="close" aria-hidden="true" data-dismiss="modal" type="button">x</button>
      </div>
      <div class="modal-body">
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-primary">Save</button>
        <button class="btn" data-dismiss="modal">Cancel</button>
      </div>
    </form>
  </div>
  </#if>
</@override>
<@override name="scripts">
<script type="text/javascript">
<#if adminUser??>
  $(document).ready(function () {
  $('#inputName').tooltip({'trigger': 'focus', 'title': '资源名字不要和文件名相同.', 'placement': 'right'});
  $('#inputPath').tooltip({'trigger': 'focus', 'title': '不以/开头是相对路径${downloadPath!}，建议用绝对路径.', 'placement': 'top'});
  $('.accessType').tooltip({'title': 'public所有人可见，private队员可见，security仅管理员可见.', 'placement': 'top'});
  $('#editModal').on('hidden', function () {
    $(this).removeData('modal');
  })
});
</#if>
</script>
</@override>
<@extends name="../common/_layout.html" />
